package com.example.h2_hsqldb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/1/17 0017.
 */

@RestController
public class DemoInfoH2Controller {
    @Autowired
    private DemoInfoH2Repository demoInfoRepository;

    /**
     * 保存数据.
     * @return
     */
    @RequestMapping("/saveh2")
    public String save(){
        // 内存数据库操作
        demoInfoRepository.save(new DemoH2Info("title1", "content1"));
        demoInfoRepository.save(new DemoH2Info("title2", "content2"));
        demoInfoRepository.save(new DemoH2Info("title3", "content3"));
        demoInfoRepository.save(new DemoH2Info("title4", "content4"));
        demoInfoRepository.save(new DemoH2Info("title5", "content5"));
        return "save ok";
    }

    /**
     * 获取所有数据.
     * @return
     */
    @RequestMapping("/findAllh2")
    public Iterable<DemoH2Info> findAll(){
        // 内存数据库操作
        return demoInfoRepository.findAll();
    }

}
